package com.lu.dog.dbrowser.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.format.DateFormat;
import android.view.View;

import com.lu.adog.adapter.recyclerview.CommonAdapter;
import com.lu.adog.adapter.recyclerview.base.ViewHolder;
import com.lu.adog.base.BaseConfig;
import com.lu.dog.dbrowser.R;
import com.lu.dog.dbrowser.bean.LogInfo;
import com.lu.dog.dbrowser.db.DBrowserDbHelper;
import com.lu.dog.dbrowser.ui.LogDesActivity;

import java.util.List;

public class LogItemAdapter extends CommonAdapter<LogInfo> {

    public LogItemAdapter(Context context, int layoutId, List datas) {
        super(context, layoutId, datas);
    }


    @Override
    protected void convert(ViewHolder holder, final LogInfo logInfo, final int position) {
        holder.setText(R.id.tv_title_log, logInfo.getTitle());
        holder.setText(R.id.tv_summary_log, logInfo.getSummary());
        String dText = (String) DateFormat.format("yyyy-MM-dd hh:mm:ss", logInfo.getCreateTime());
        holder.setText(R.id.tv_date_log, dText);

        holder.setOnClickListener(R.id.lc_visit_log, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, LogDesActivity.class);
                intent.putExtra(BaseConfig.KEY_LOG_ID,logInfo.getId());
                mContext.startActivity(intent);
            }
        });
        holder.setOnClickListener(R.id.iv_delete_log, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getDatas().remove(position);
                notifyDataSetChanged();
                DBrowserDbHelper.getInstance(mContext).deleteLogInfo(logInfo);
            }
        });

    }
}
